package cn.school.service;

import java.util.Date;
import java.util.List;

import cn.school.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import cn.school.dao.StudentDao;
import cn.school.entity.Student;

public class StudentService {

    public List<Student> search(int pageNo, int pageSize, String name, String tele,String qq, Date enterDateStart,
                                Date enterEnd) {
        SqlSession s = MyBatisUtil.get();
        try {
            StudentDao studentDao = s.getMapper(StudentDao.class);
            return studentDao.search(pageNo, pageSize, name, tele,qq, enterDateStart, enterEnd);
        } finally {
            MyBatisUtil.close(s);
        }
    }

    public int add(Student student){
        SqlSession s = MyBatisUtil.get();
        try{
            StudentDao studentDao = s.getMapper(StudentDao.class);
            return studentDao.add(student);
        }finally {
            MyBatisUtil.close(s);
        }
    }

    public int searchTotal(String name, String tele, String qq, Date enterDateStart,  Date enterEnd){
        SqlSession s = MyBatisUtil.get();
        try{
            StudentDao studentDao = s.getMapper(StudentDao.class);
            return studentDao.searchTotal(name,tele,qq,enterDateStart,enterEnd);
        }finally {
            MyBatisUtil.close(s);
        }
    }

    public Student selectById(int id){
        SqlSession s = MyBatisUtil.get();
        try{
            StudentDao studentDao = s.getMapper(StudentDao.class);
            return studentDao.selectById(id);
        }finally {
            MyBatisUtil.close(s);
        }
    }

    public int update(Student student){
        SqlSession s = MyBatisUtil.get();
        try{
            StudentDao studentDao = s.getMapper(StudentDao.class);
            return studentDao.update(student);
        }finally {
            MyBatisUtil.close(s);
        }
    }

    public int delstu(int id){
        SqlSession s = MyBatisUtil.get();
        try{
            StudentDao studentDao = s.getMapper(StudentDao.class);
            return studentDao.delstu(id);
        }finally {
            MyBatisUtil.close(s);
        }
    }
}